.class public Lcom/glympse/platform/common/MessageList;
.super Ljava/lang/Object;
.source "MessageList.java"


# static fields
.field private static final FILE_NAME:Ljava/lang/String; = "messages"


# instance fields
.field public m_listMessages:Lcom/glympse/platform/GVector$Messages;


# direct methods
.method public constructor <init>()V
    .locals 1

    .prologue
    .line 20
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 24
    new-instance v0, Lcom/glympse/platform/GVector$Messages;

    invoke-direct {v0}, Lcom/glympse/platform/GVector$Messages;-><init>()V

    iput-object v0, p0, Lcom/glympse/platform/common/MessageList;->m_listMessages:Lcom/glympse/platform/GVector$Messages;

    .line 20
    return-void
.end method

.method private Save()V
    .locals 5

    .prologue
    .line 120
    new-instance v1, Lcom/glympse/platform/GFile;

    invoke-direct {v1}, Lcom/glympse/platform/GFile;-><init>()V

    .line 121
    .local v1, oGFile:Lcom/glympse/platform/GFile;
    const-string v4, "messages"

    invoke-virtual {v1, v4}, Lcom/glympse/platform/GFile;->OpenForOutput(Ljava/lang/String;)Z

    move-result v4

    if-nez v4, :cond_0

    .line 141
    :goto_0
    return-void

    .line 126
    :cond_0
    new-instance v3, Ljava/lang/StringBuffer;

    invoke-direct {v3}, Ljava/lang/StringBuffer;-><init>()V

    .line 128
    .local v3, strbuf:Ljava/lang/StringBuffer;
    iget-object v4, p0, Lcom/glympse/platform/common/MessageList;->m_listMessages:Lcom/glympse/platform/GVector$Messages;

    invoke-virtual {v4}, Lcom/glympse/platform/GVector$Messages;->elements()Ljava/util/Enumeration;

    move-result-object v0

    .local v0, iterMessage:Ljava/util/Enumeration;
    :goto_1
    invoke-interface {v0}, Ljava/util/Enumeration;->hasMoreElements()Z

    move-result v4

    if-nez v4, :cond_1

    .line 140
    invoke-virtual {v1}, Lcom/glympse/platform/GFile;->Close()V

    goto :goto_0

    .line 130
    :cond_1
    invoke-interface {v0}, Ljava/util/Enumeration;->nextElement()Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Lcom/glympse/platform/common/Message;

    .line 133
    .local v2, oMessageCur:Lcom/glympse/platform/common/Message;
    const/4 v4, 0x0

    invoke-virtual {v3, v4}, Ljava/lang/StringBuffer;->setLength(I)V

    .line 134
    invoke-virtual {v2, v3}, Lcom/glympse/platform/common/Message;->Serialize(Ljava/lang/StringBuffer;)V

    .line 137
    invoke-virtual {v3}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v4

    invoke-virtual {v1, v4}, Lcom/glympse/platform/GFile;->WriteLine(Ljava/lang/String;)Z

    goto :goto_1
.end method


# virtual methods
.method public Add(Ljava/lang/String;)V
    .locals 4
    .parameter "strMessage"

    .prologue
    .line 54
    invoke-static {p1}, Lcom/glympse/platform/common/Helpers;->IsEmpty(Ljava/lang/String;)Z

    move-result v1

    if-nez v1, :cond_1

    .line 57
    invoke-virtual {p0, p1}, Lcom/glympse/platform/common/MessageList;->Find(Ljava/lang/String;)Lcom/glympse/platform/common/Message;

    move-result-object v0

    .line 58
    .local v0, oMessageFound:Lcom/glympse/platform/common/Message;
    if-eqz v0, :cond_0

    .line 60
    iget-object v1, p0, Lcom/glympse/platform/common/MessageList;->m_listMessages:Lcom/glympse/platform/GVector$Messages;

    invoke-virtual {v1, v0}, Lcom/glympse/platform/GVector$Messages;->removeElement(Ljava/lang/Object;)Z

    .line 64
    :cond_0
    iget-object v1, p0, Lcom/glympse/platform/common/MessageList;->m_listMessages:Lcom/glympse/platform/GVector$Messages;

    new-instance v2, Lcom/glympse/platform/common/Message;

    invoke-direct {v2, p1}, Lcom/glympse/platform/common/Message;-><init>(Ljava/lang/String;)V

    const/4 v3, 0x0

    invoke-virtual {v1, v2, v3}, Lcom/glympse/platform/GVector$Messages;->insertElementAt(Ljava/lang/Object;I)V

    .line 67
    invoke-direct {p0}, Lcom/glympse/platform/common/MessageList;->Save()V

    .line 69
    .end local v0           #oMessageFound:Lcom/glympse/platform/common/Message;
    :cond_1
    return-void
.end method

.method protected Clear()V
    .locals 1

    .prologue
    .line 114
    iget-object v0, p0, Lcom/glympse/platform/common/MessageList;->m_listMessages:Lcom/glympse/platform/GVector$Messages;

    invoke-virtual {v0}, Lcom/glympse/platform/GVector$Messages;->removeAllElements()V

    .line 115
    return-void
.end method

.method public Find(Ljava/lang/String;)Lcom/glympse/platform/common/Message;
    .locals 3
    .parameter "strMessage"

    .prologue
    .line 74
    invoke-static {p1}, Lcom/glympse/platform/common/Helpers;->IsEmpty(Ljava/lang/String;)Z

    move-result v2

    if-nez v2, :cond_1

    .line 76
    iget-object v2, p0, Lcom/glympse/platform/common/MessageList;->m_listMessages:Lcom/glympse/platform/GVector$Messages;

    invoke-virtual {v2}, Lcom/glympse/platform/GVector$Messages;->elements()Ljava/util/Enumeration;

    move-result-object v0

    .local v0, iterMessage:Ljava/util/Enumeration;
    :cond_0
    invoke-interface {v0}, Ljava/util/Enumeration;->hasMoreElements()Z

    move-result v2

    if-nez v2, :cond_2

    .line 86
    .end local v0           #iterMessage:Ljava/util/Enumeration;
    :cond_1
    const/4 v2, 0x0

    :goto_0
    return-object v2

    .line 78
    .restart local v0       #iterMessage:Ljava/util/Enumeration;
    :cond_2
    invoke-interface {v0}, Ljava/util/Enumeration;->nextElement()Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Lcom/glympse/platform/common/Message;

    .line 80
    .local v1, oMessageCur:Lcom/glympse/platform/common/Message;
    iget-object v2, v1, Lcom/glympse/platform/common/Message;->m_strMessage:Ljava/lang/String;

    invoke-virtual {v2, p1}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v2

    if-eqz v2, :cond_0

    move-object v2, v1

    .line 82
    goto :goto_0
.end method

.method public Load()Z
    .locals 5

    .prologue
    .line 146
    const/4 v0, 0x0

    .line 149
    .local v0, fSuccess:Z
    new-instance v2, Lcom/glympse/platform/GFile;

    invoke-direct {v2}, Lcom/glympse/platform/GFile;-><init>()V

    .line 150
    .local v2, oGFile:Lcom/glympse/platform/GFile;
    const-string v4, "messages"

    invoke-virtual {v2, v4}, Lcom/glympse/platform/GFile;->OpenForInput(Ljava/lang/String;)Z

    move-result v4

    if-eqz v4, :cond_0

    .line 152
    const/4 v0, 0x1

    .line 155
    const/4 v1, 0x0

    .line 156
    .local v1, listNameValues:Lcom/glympse/platform/GVector$NameValueNodes;,"Lcom/glympse/platform/GVector$NameValueNodes;"
    :goto_0
    invoke-virtual {v2}, Lcom/glympse/platform/GFile;->ReadLine()Lcom/glympse/platform/GVector$NameValueNodes;

    move-result-object v1

    if-nez v1, :cond_1

    .line 169
    .end local v1           #listNameValues:Lcom/glympse/platform/GVector$NameValueNodes;,"Lcom/glympse/platform/GVector$NameValueNodes;"
    :cond_0
    invoke-virtual {v2}, Lcom/glympse/platform/GFile;->Close()V

    .line 171
    return v0

    .line 159
    .restart local v1       #listNameValues:Lcom/glympse/platform/GVector$NameValueNodes;,"Lcom/glympse/platform/GVector$NameValueNodes;"
    :cond_1
    new-instance v3, Lcom/glympse/platform/common/Message;

    invoke-direct {v3}, Lcom/glympse/platform/common/Message;-><init>()V

    .line 162
    .local v3, oMessage:Lcom/glympse/platform/common/Message;
    invoke-virtual {v3, v1}, Lcom/glympse/platform/common/Message;->Parse(Lcom/glympse/platform/GVector$NameValueNodes;)V

    .line 165
    iget-object v4, p0, Lcom/glympse/platform/common/MessageList;->m_listMessages:Lcom/glympse/platform/GVector$Messages;

    invoke-virtual {v4, v3}, Lcom/glympse/platform/GVector$Messages;->addElement(Ljava/lang/Object;)V

    goto :goto_0
.end method

.method public MoveToTop(Lcom/glympse/platform/common/Message;)V
    .locals 2
    .parameter "oMessage"

    .prologue
    .line 93
    iget-object v0, p0, Lcom/glympse/platform/common/MessageList;->m_listMessages:Lcom/glympse/platform/GVector$Messages;

    invoke-virtual {v0, p1}, Lcom/glympse/platform/GVector$Messages;->removeElement(Ljava/lang/Object;)Z

    .line 94
    iget-object v0, p0, Lcom/glympse/platform/common/MessageList;->m_listMessages:Lcom/glympse/platform/GVector$Messages;

    const/4 v1, 0x0

    invoke-virtual {v0, p1, v1}, Lcom/glympse/platform/GVector$Messages;->insertElementAt(Ljava/lang/Object;I)V

    .line 97
    invoke-direct {p0}, Lcom/glympse/platform/common/MessageList;->Save()V

    .line 98
    return-void
.end method

.method public Remove(Lcom/glympse/platform/common/Message;)V
    .locals 1
    .parameter "oMessage"

    .prologue
    .line 104
    iget-object v0, p0, Lcom/glympse/platform/common/MessageList;->m_listMessages:Lcom/glympse/platform/GVector$Messages;

    invoke-virtual {v0, p1}, Lcom/glympse/platform/GVector$Messages;->removeElement(Ljava/lang/Object;)Z

    .line 107
    invoke-direct {p0}, Lcom/glympse/platform/common/MessageList;->Save()V

    .line 108
    return-void
.end method

.method public Start()V
    .locals 5

    .prologue
    .line 29
    invoke-virtual {p0}, Lcom/glympse/platform/common/MessageList;->Clear()V

    .line 32
    invoke-virtual {p0}, Lcom/glympse/platform/common/MessageList;->Load()Z

    move-result v2

    if-nez v2, :cond_0

    .line 34
    invoke-virtual {p0}, Lcom/glympse/platform/common/MessageList;->Clear()V

    .line 37
    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v2

    invoke-virtual {v2}, Lcom/glympse/platform/Platform;->GetCannedMessages()[Ljava/lang/String;

    move-result-object v0

    .line 38
    .local v0, astrCannedMessages:[Ljava/lang/String;
    const/4 v1, 0x0

    .local v1, nMessage:I
    :goto_0
    array-length v2, v0

    if-lt v1, v2, :cond_1

    .line 43
    .end local v0           #astrCannedMessages:[Ljava/lang/String;
    .end local v1           #nMessage:I
    :cond_0
    return-void

    .line 40
    .restart local v0       #astrCannedMessages:[Ljava/lang/String;
    .restart local v1       #nMessage:I
    :cond_1
    iget-object v2, p0, Lcom/glympse/platform/common/MessageList;->m_listMessages:Lcom/glympse/platform/GVector$Messages;

    new-instance v3, Lcom/glympse/platform/common/Message;

    aget-object v4, v0, v1

    invoke-direct {v3, v4}, Lcom/glympse/platform/common/Message;-><init>(Ljava/lang/String;)V

    invoke-virtual {v2, v3}, Lcom/glympse/platform/GVector$Messages;->addElement(Ljava/lang/Object;)V

    .line 38
    add-int/lit8 v1, v1, 0x1

    goto :goto_0
.end method

.method public Stop()V
    .locals 0

    .prologue
    .line 48
    invoke-virtual {p0}, Lcom/glympse/platform/common/MessageList;->Clear()V

    .line 49
    return-void
.end method
